using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class ClickEffectGrid : Grid
	{
		private const double cDMoveRestrict = 25.0;
		private DateTime mTimeLastClicked;
		private bool mBIsClickCancled;
		private DateTime mTimeStarted;
		private Border borderCover;
		public static DependencyProperty ForgroundNormalProperty = DependencyProperty.Register("ForgroundNormal", typeof(SolidColorBrush), typeof(ClickEffectGrid), new PropertyMetadata(null, new PropertyChangedCallback(ClickEffectGrid.OnForgroundNormalPropertyChanged)));
		public static DependencyProperty ForgroundFocusProperty = DependencyProperty.Register("ForgroundFocus", typeof(SolidColorBrush), typeof(ClickEffectGrid), new PropertyMetadata(null, new PropertyChangedCallback(ClickEffectGrid.OnForgroundFocusPropertyChanged)));
		public static DependencyProperty BackgroudNormalProperty = DependencyProperty.Register("BackgroudNormal", typeof(SolidColorBrush), typeof(ClickEffectGrid), new PropertyMetadata(null, new PropertyChangedCallback(ClickEffectGrid.OnBackgroudNormalPropertyChanged)));
		public static DependencyProperty BackgroudFocusProperty = DependencyProperty.Register("BackgroudFocus", typeof(SolidColorBrush), typeof(ClickEffectGrid), new PropertyMetadata(null, new PropertyChangedCallback(ClickEffectGrid.OnBackgroudFocusPropertyChanged)));
		public event MMStandardUIEvent mClicked;
		public SolidColorBrush ForgroundNormal
		{
			get
			{
				return (SolidColorBrush)base.GetValue(ClickEffectGrid.ForgroundNormalProperty);
			}
			set
			{
				base.SetValue(ClickEffectGrid.ForgroundNormalProperty, value);
			}
		}
		public SolidColorBrush ForgroundFocus
		{
			get
			{
				return (SolidColorBrush)base.GetValue(ClickEffectGrid.ForgroundFocusProperty);
			}
			set
			{
				base.SetValue(ClickEffectGrid.ForgroundFocusProperty, value);
			}
		}
		public SolidColorBrush BackgroudNormal
		{
			get
			{
				return (SolidColorBrush)base.GetValue(ClickEffectGrid.BackgroudNormalProperty);
			}
			set
			{
				base.SetValue(ClickEffectGrid.BackgroudNormalProperty, value);
			}
		}
		public SolidColorBrush BackgroudFocus
		{
			get
			{
				return (SolidColorBrush)base.GetValue(ClickEffectGrid.BackgroudFocusProperty);
			}
			set
			{
				base.SetValue(ClickEffectGrid.BackgroudFocusProperty, value);
			}
		}
		public ClickEffectGrid()
		{
			base.add_Tap(new EventHandler<GestureEventArgs>(this.ClickEffectGrid_Tap));
			base.add_ManipulationStarted(new EventHandler<ManipulationStartedEventArgs>(this.ClickEffectGrid_ManipulationStarted));
			base.add_ManipulationDelta(new EventHandler<ManipulationDeltaEventArgs>(this.ClickEffectGrid_ManipulationDelta));
			base.add_ManipulationCompleted(new EventHandler<ManipulationCompletedEventArgs>(this.ClickEffectGrid_ManipulationCompleted));
		}
		private void ClickEffectGrid_Tap(object sender, GestureEventArgs e)
		{
			if (this.mBIsClickCancled)
			{
				return;
			}
			DateTime now = DateTime.get_Now();
			double totalMilliseconds = now.Subtract(this.mTimeLastClicked).get_TotalMilliseconds();
			if (totalMilliseconds < 500.0)
			{
				return;
			}
			this.mTimeLastClicked = now;
			if (this.mClicked != null)
			{
				this.mClicked(this, null);
			}
			this.mBIsClickCancled = true;
		}
		private void ClickEffectGrid_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			this.mBIsClickCancled = false;
			if (this.BackgroudFocus != null)
			{
				base.set_Background(this.BackgroudFocus);
			}
			this.turnOnForCover();
			this.mTimeStarted = DateTime.get_Now();
		}
		private void ClickEffectGrid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
		{
			Point translation = e.get_DeltaManipulation().get_Translation();
			if (translation.get_X() * translation.get_X() + translation.get_Y() * translation.get_Y() > 25.0)
			{
				this.mBIsClickCancled = true;
				if (this.BackgroudNormal != null)
				{
					base.set_Background(this.BackgroudNormal);
				}
				this.turnOffForCover();
			}
		}
		private void ClickEffectGrid_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			if (this.BackgroudNormal != null)
			{
				base.set_Background(this.BackgroudNormal);
			}
			this.turnOffForCover();
			if (!this.mBIsClickCancled && this.mClicked != null)
			{
				DateTime now = DateTime.get_Now();
				if ((now - this.mTimeStarted).get_TotalMilliseconds() < 250.0)
				{
					base.get_Dispatcher().BeginInvoke(delegate
					{
						this.ClickEffectGrid_Tap(null, null);
					});
				}
			}
		}
		private void turnOnForCover()
		{
			if (this.ForgroundFocus != null)
			{
				if (this.borderCover == null)
				{
					this.borderCover = new Border();
				}
				this.borderCover.set_Background(this.ForgroundFocus);
				base.get_Children().Remove(this.borderCover);
				base.get_Children().Add(this.borderCover);
			}
		}
		private void turnOffForCover()
		{
			if (this.borderCover != null && this.borderCover.get_Parent() != null)
			{
				base.get_Children().Remove(this.borderCover);
			}
		}
		private static void OnForgroundNormalPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ClickEffectGrid.ForgroundNormalProperty)
			{
				(dependencyObject_0 as ClickEffectGrid).ForgroundNormalPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void ForgroundNormalPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		private static void OnForgroundFocusPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ClickEffectGrid.ForgroundFocusProperty)
			{
				(dependencyObject_0 as ClickEffectGrid).ForgroundFocusPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void ForgroundFocusPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		private static void OnBackgroudNormalPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ClickEffectGrid.BackgroudNormalProperty)
			{
				(dependencyObject_0 as ClickEffectGrid).BackgroudNormalPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void BackgroudNormalPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		private static void OnBackgroudFocusPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ClickEffectGrid.BackgroudFocusProperty)
			{
				(dependencyObject_0 as ClickEffectGrid).BackgroudFocusPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void BackgroudFocusPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
	}
}
